<template>
  <div>
    <el-table :data="userList" style="width: 100%" stripe border>
      <el-table-column prop="username" label="名字" align="center">
      </el-table-column>
      <el-table-column prop="email" label="邮箱" align="center">
      </el-table-column>
      <el-table-column prop="mobile" label="电话" align="center">
      </el-table-column>
      <el-table-column prop="role_name" label="超级管理员" align="center">
      </el-table-column>
      <el-table-column prop="mg_state" label="状态" align="center">
        <template v-slot:default="scope">
          <el-switch
            v-model="scope.row.mg_state"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </template>
      </el-table-column>
      <!-- 管理用户 -->
      <el-table-column prop="" label="操作" align="center">
        <el-tooltip effect="dark" content="编辑用户" placement="top-start">
          <el-button icon="el-icon-edit"></el-button>
        </el-tooltip>
        <el-tooltip effect="dark" content="删除用户" placement="top-start">
          <el-button icon="el-icon-delete"></el-button>
        </el-tooltip>
        <el-tooltip effect="dark" content="分配用户权限" placement="top-start">
          <el-button icon="el-icon-setting"></el-button>
        </el-tooltip>
      </el-table-column>
    </el-table>
    <!-- 分页管理 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="userPage.page"
      :page-sizes="[1, 3, 5, 10]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="userPage.total"
    >
    </el-pagination>
  </div>
</template>

<script>
/* 网络请求 */
import { getUserList } from "@/api/user";
export default {
  // props: {
  //   userList: {
  //     type: Array,
  //   },
  //   userPage: {
  //     type: Object,
  //   },
  // },
  data() {
    return {
      pageSize: 1,
      reqData: {
        query: "",
        pagenum: 1,
        pagesize: 2,
      },
      userList: [],
      userPage:{
        pagenum:'',
        total:4
      }
    };
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val;
      this.user()
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.userPage.pagenum = val;
      this.user()
      console.log(`当前页: ${val}`);
    },
    /* 网络请求 */
    async user() {
      const { data: res } = await getUserList(this.reqData);
      console.log(res);
      this.userList = res.data.users; //获取用户信息
      this.reqData.pagenum = res.data.pagenum; //当前的页数
      this.userPage.total = res.data.total; //获取总页数
    },
  },
  created() {
    this.user();
  },
};
</script>

<style lang="scss" scoped>
</style>